<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/17 0017
 * Time: 下午 2:22
 */
namespace App\Api\Service\Warehouse\Controllers;

use App\Eloquent\Ygt\Customer;
use App\Eloquent\Ygt\DepartmentUser;
use App\Engine\Func;
use Framework\BaseClass\Api\Controller;


class CustomerController extends Controller
{

    public $userId      = 25;
    public function lists()
    {
        $userId             = Func::getHeaderValueByName('userid',$this->userId);
        $userInfo           = DepartmentUser::getCurrentInfo($userId);
        if( !$userInfo )
        {
            xThrow( ERR_PARAMETER );
        }
        $companyId          = $userInfo->company_id;
        $where              = ['company_id'=>$companyId];
        $collection         = Customer::getList($where);
        $letterArr          = $collection->pluck('first_letter')->all();
        $lists              = [];
        if($letterArr)
        {
            $letterArr      = array_unique($letterArr);
            sort($letterArr);
            $listArr            = $collection->groupBy('first_letter')->toArray();
            foreach($letterArr as $key=>$val)
            {
                $lists[$key]['letter']      = $val;
                $lists[$key]['list']       = $listArr[$val];
            }
        }
        return $lists;
    }
}